<template>
	<view :class="['qn-page-' + theme]">
		<view class="search-input clearfix">
			<view class="input-box float_left">
				<u-search
					@click="goPage('/pages/search/index', 'redirectTo')"
					placeholder="请输入关键字"
					:input-style="input_style"
					:search-icon-color="primaryColor"
					v-model="keyword"
					:show-action="false"
					shape="square"
					:clearabled="true"
					bg-color="#f4f4f4"
					disabled
				></u-search>
			</view>
			<view class="float_right type-view" @click="changeStyle"><text class="ibonfont" :class="[is_list ? 'ibonfenlei1' : 'ibonfenlei2']"></text></view>
		</view>
		<view class="goods-ul">
			<Aempty text="没有商品哦～～" src="../../static/empty/data.png" v-if="!goods_list.length"></Aempty>
			<block v-for="(item, index) in goods_list" :key="index"><GoodsItem :isList="is_list" :item="item" @addCart="addCart"></GoodsItem></block>
			<u-loadmore v-if="goods_list.length" :status="load_status" />
		</view>
		<AddCardModel @close="closeaddcartPop" :isShow="show_sku" :goodsId="goods_id"></AddCardModel>
	</view>
</template>

<script>
import AddCardModel from '@/components/AddCardModel';
import GoodsItem from '../../components/GoodsItem.vue';
import NoLoginTip from '@/components/NoLoginTip.vue';
export default {
	components: {
		GoodsItem,
		AddCardModel,
	},
	data() {
		return {
			show_sku: false,
			is_list: false,
			keyword: '',
			goods_list: [],
			page: 1,
			pageSize: 10,
			pageTotal: 0,
			goods_id: 0,
			load_status: 'loadmore'
		};
	},
	onLoad(options) {
		this.keyword = options.keyword;
		this.searchGoods();
	},
	methods: {
		// 加入购物车弹窗
		addCart(row) {
			this.goods_id = row.id;
			this.show_sku = true;
		},
		// 关闭加入购物车弹窗
		closeaddcartPop() {
			this.show_sku = false;
		},
		// 切换商品列表展示样式
		changeStyle() {
			this.is_list = !this.is_list;
		},
		// 商品搜索
		searchGoods() {
			this.loadStatus = 'loading';
			this.$u.api
				.searchGoods({
					page: this.page,
					pageSize: this.pageSize,
					keyword: this.keyword,
					categoryId: '',
					enableStatus: 5
				})
				.then(res => {
					if (this.page === 1) {
						this.goods_list = res.data;
					} else {
						this.goods_list = this.goods_list.concat(res.data);
					}
					this.pageTotal = res.pageTotal;
					this.load_status = this.$utils.loadStatus(this.goods_list, res.pageTotal);
				});
		}
	}
};
</script>

<style lang="scss">
.search-input {
	background-color: #ffffff;
	padding: 22upx;
	.input-box {
		width: 620rpx;
	}
	.type-view {
		width: 80rpx;
		text-align: center;
		line-height: 64upx;
		height: 64upx;
		.ibonfont {
			font-size: 36upx;
			color: #909399;
		}
	}
}
.goods-ul {
	padding-top: 20upx;
}
</style>
